package com.cysion.study.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.cysion.study.ktbox.base.BaseAdapter
import com.cysion.study.ktbox.base.BaseViewHolder
import com.cysion.other._setOnClickListener
import com.cysion.study.R
import com.cysion.study.entity.NoticeEntity
import kotlinx.android.synthetic.main.item_notice.view.*

class NoticeAdapter(mEntities: MutableList<NoticeEntity>, mContext: Context) :
    BaseAdapter<NoticeEntity>(mEntities, mContext) {

    companion object {

        //点击事件
        const val refuse = 2000
        const val agree = 2001
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<NoticeEntity> {
        return ProMoneyHolder(
            LayoutInflater.from(mContext).inflate(R.layout.item_notice, parent, false)
        )
    }

    class ProMoneyHolder(itemView: View) : BaseViewHolder<NoticeEntity>(itemView) {
        override fun fillData(obj: NoticeEntity, position: Int) {
            itemView?.apply {
                //                itemView.tv_data.text=
                //isRead":0, //是否已读 0.未读 1.已读
                if (obj.isRead == "0") {
                    tv_hint.visibility = View.VISIBLE
                } else {
                    tv_hint.visibility = View.GONE
                }

                tv_time.text = obj.createTime
                tv_data.text = obj.createTime
                tv_title.text = obj.title
                tv_content.text = obj.content
                //type":0, //通知类型 0.机构任职通知 1.机构撤销通知 2.课程负责通知
                // 3.课程授课通知 4.开课通知 5.活动通知 6.开营通知 7.考勤通知
                /*if (obj.type == "0") {
                    ll_btn.visibility = View.VISIBLE
                    tv_more.visibility = View.GONE
                } else {
                    ll_btn.visibility = View.GONE
                    tv_more.visibility = View.VISIBLE
                }*/
                //...
                //"isConfirm":1, //是否需要确认 0.不需要 1.需要确认
                var isConfirm: Boolean
                if (obj.isConfirm == "0") {
                    isConfirm = false
                    ll_btn.visibility = View.GONE
                    tv_more.visibility = View.VISIBLE
                    //"confirmResult":0,  //确认的结: 0.待确认 1.同意 2.拒绝
                    //当通知需要确认时必填 1.同意 2.拒绝
                    when {
                        obj.confirmResult == "0" -> {
                            tv_refuse.visibility=View.VISIBLE
                            tv_agree.visibility=View.VISIBLE
                            tv_agree.isEnabled=true
                            tv_refuse.isEnabled=true
                        }
                        obj.confirmResult == "1" -> {
                            tv_refuse.visibility=View.GONE
                            tv_agree.visibility=View.VISIBLE
                            tv_agree.text="已同意"
                            tv_agree.isEnabled=false
                        }
                        obj.confirmResult == "2" -> {
                            tv_refuse.visibility=View.VISIBLE
                            tv_agree.visibility=View.GONE
                            tv_refuse.text="已拒绝"
                            tv_refuse.isEnabled=false
                        }
                    }
                } else {
                    isConfirm = true
                    ll_btn.visibility = View.VISIBLE
                    tv_more.visibility = View.GONE
                }

                //isRead":0, //是否已读 0.未读 1.已读
                tv_agree._setOnClickListener {
                    //当通知需要确认时必填 1.同意 2.拒绝
                    mOnTypeClickListener?.invoke(obj, position, agree)
                }
                tv_refuse._setOnClickListener {
                    mOnTypeClickListener?.invoke(obj, position, refuse)
                }
            }
        }

    }
}